#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>

int find_word(char *date, char *buf) {
    FILE *fp = fopen("Dictionary.txt", "r");
    if (fp == NULL) {
        perror("无法打开文件");
        return 0;
    }

    char line[259];
    int found = 0;

    while (fgets(line, sizeof(line), fp)) {
        line[strcspn(line, "\n")] = 0; // 去除换行符

        char *current = line;

        // 跳过空格或制表符
        while (*current == ' ' || *current == '\t') {
            current++;
        }

        // 提取单词
        char *word_start = current;
        while (*current != ' ' && *current != '\t' && *current != '\0') {
            current++;
        }

        // 分隔单词
        *current = '\0';
        current++;

        // 跳过单词后的空格或制表符
        while (*current == ' ' || *current == '\t') {
            current++;
        }

        // 此时current指向了单词后面的第一个内容
        // 检查是否匹配
        if (strcmp(word_start, date) == 0) {
            // 定义部分
            strcpy(buf, current);
            found = 1;
            break;
        }
    }

    fclose(fp);
    return found;
}


int main() {
    char p[50] = {0};
    char a[50] = {0};
    printf("请输入单词：");
    scanf("%s", a);
    find_word(a, p);
    printf("%s", p);
}